Repository navigation
feat(cli): cloudhal import --replace and --revert (#47, step 4) - #132
Merged
Merged
Conversation
restoreBundle(from, snapshot) rebuilds a site bundle from a snapshot's stored node bodies, for importSite in replace mode, so a site's working copy and published pointer can become that snapshot's again (the undo of `cloudhal import --replace`, RFC-0039). Revs only move forward: a node the site holds at the snapshot's rev or later, with other content, comes back at the rev after its current one, so a stale editor gets a conflict. It lists the media the nodes need and carries the store's takedowns. A missing or mismatched body is refused before anything is written. exportSite's output is unchanged; its takedown query and media rule are shared. Refs #47 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
RFC-0039 rollout step 4. - `import <file> --replace` makes the local site's nodes the archive's, its published snapshot included (as pull --replace; push still keeps a deployment's own). When it changes a site the project holds, the current graph is saved first as `before import <file>` and the result as `import <file>`; the summary prints the undo. - `import --revert <snapshot-id>` brings the site back to such a snapshot through restoreBundle and importSite, saving the current graph first, so a revert can itself be reverted. Studio's rollback only moves the published pointer to an ancestor, which cannot undo a replace. - An archive of a site cloudhal.json does not list switches siteId (and the old id's place in sites), editing only those values once the import has landed; the old site stays in the store, untouched. - Refused before anything is written: open releases, an unfinished field operation, a hostname another local site serves. - --cancel-schedules is now refused by every command but push. RFC-0039 §2 and invariant 6 and ADR-0041 decision 4 are amended to name the undo and the published-pointer choice. Refs #47 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Step 4 of RFC-0039's rollout for #47:
cloudhal import <file> --replace [--dry-run], thebefore importsnapshot, and the switch to the archive's site id. It also addscloudhal import --revert <snapshot-id> [--dry-run]as the undo (see "For the owner").--replacepull --replace;pushstill keeps a deployment's own pointer, so a local replace never moves production.before import <file>and the result asimport <file>. The summary prints(undo: cloudhal import --revert <id>).--revert <id>restoreBundle(new, core-ts, Worker-safe) rebuilds the site from that snapshot's stored bodies, andimportSiteapplies it in replace mode. The published snapshot is restored too.before revert import <file>, so a revert can itself be reverted.cloudhal.json, onlysiteIdand the old id's entry insitesare edited. The layout and other keys stay as written. The edit is atomic, happens after the import has landed, and a concurrent edit of the file is refused. The old site stays in the local store, untouched; writing the old id back undoes the switch. A deployed project gets a warning that its deployment serves the old site. That warning reads onlystate.json, never the secrets.--dry-runreports, for bootstrap imports too.--cancel-schedulesis now refused by every command exceptpush.For the owner
--replace"can be undone with a rollback", but no such rollback exists: Studio's rollback only moves the published pointer, and only to an ancestor of the published snapshot. Thebefore importsnapshot is never an ancestor, so--revertwas added. It follows the repo's existing--revert <id>pattern (media import-urls,migrate).--replacetakes the archive's published pointer, likepull --replace. The issue mentioned "likepush --replace" (keep the target's). For a local restore, the archive's pointer is what brings the backup back, and the deployment keeps its own on push.--replace: archive nodes keep their revs, as withpull --replace, so the local site equals the archive and later push/pull against its deployment don't conflict. A Studio tab holding the same rev could therefore save over a replaced node without a conflict. The summary and dry run count those nodes and say to reload open tabs.--revertdoesn't have this problem because its revs move forward.Verification (local)
packages/core-ts: the full suite passes, 56 files and 1002 tests. That includes the newsync-restore.test.tsand the sqlite and Miniflare D1 behavioural suites.packages/cli:import-replace(14),import-switch(10),import-cli(25),export-cli,cli-commandsandarchive-*all pass, 206 tests in one process. Two mutation checks confirm the tests catch regressions:cloudhal.jsonbefore the import fails the switch tests;init→snapshot --publish→export→ local edit →import --replace --dry-run(exit 0, shows the snapshots and the pointer change).import --replace, thenimport --revert <before-id> --dry-run, then--revert: the edit came back and its revs moved forward.cloudhal.jsonby exactly one line, andsite listshows both sites.pnpm size:checkpass.Checklist
pnpm checkandcargo test --workspacepass locally. Full core-ts suite plus the CLI pieces that cover this change; there is no Rust or contract change, and CI runs the rest..changeset/site-archive-replace.md(cli).changeset/restore-bundle.md(core-ts)site-archive-import.mdupdatedgit commit -s, DCO)help.tsand the RFC/ADR amendments are updated; the guide comes in step 5.Refs #47
🤖 Generated with Claude Code